﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ylh.FactoryDAL;
using ExtAspNet;

public partial class Module_StaffManger_ChangeStaffPwd : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Cancel.OnClientClick = ActiveWindow.GetHideReference();
    }


    protected void btnChangePwd_Click(object sender, EventArgs e)
    {
        try
        {
            Ylh.IDAL.IStaff Istaff = DataAccess.CreateIStaff();

            if (newPWD1.Text != newPWD2.Text)
            {
                Alert.Show("两次密码不一致,请重新输入!");
                newPWD1.Text = "";
                newPWD2.Text = "";
                return;
            }

            int res = Istaff.UpdateStaffPwd(DbConnectionStr, Convert.ToInt32(base.StaffID), oldPWD.Text, newPWD1.Text);
            if (res > 0)
            {
                
                Alert.Show("修改密码成功!");
                PageContext.RegisterStartupScript(ActiveWindow.GetHideReference());
            }
            else if (res == 0)
            {
                Alert.Show("原密码错误,请重新输入!");
                oldPWD.Text = "";
            }
            else
            {
                Alert.Show("修改密码失败!");
            }
        }
        catch (Exception ex)
        {
            ExtAspNet.Alert.ShowInTop(ex.Message.ToString());
            throw;
        }

    }
}